/*
 * 文件名：PageDTO.java
 * 版权：MoonBox 
 * 修改人：Peter
 * 修改时间：2018年10月15日
 * 修改内容：新增
 */
package com.renzhebiao.lkang.page;

import java.util.Collections;
import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <p>
 * 
 * @author Peter
 * @since 1.0.0
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "page", description = "分页记录")
public class PageDTO<T> extends PaginationDTO {

    /**
     * 查询数据列表
     */
    @ApiModelProperty(value = "查询结果数据列表")
    private List<T> records = Collections.emptyList();

    /**
     * 总页数
     */
    @ApiModelProperty(value = "总页数")
    private Integer pages;

    public PageDTO(Integer current, Integer size, Integer total, Integer pages) {
        this.pages = pages;
        this.setTotal(total);
        this.setSize(size);
        this.setCurrent(current);
    }

    public int getPages() {
        int size = this.getSize();
        int total = this.getTotal();
        if (size == 0) {
            return 0;
        }
        this.pages = total / size;
        if (total % size != 0) {
            this.pages++;
        }
        return this.pages;
    }

}
